/**
 * Actively Replicated Crash Free Single Software Failure (non Byzantine)
 * Distributed Retail Store 
 * 
 * November 28 2012
 */
package comp6231.project.common;

/**
 * Timer 
 * @author dimitritiago
 */
public class UDPTimer extends Thread
{
	private ReliableUDPSocket reliableUDPSocket;
	private long timeout;
	private Boolean cancel;
	
	public UDPTimer(ReliableUDPSocket reliableUDPSocket, long timeout)
	{
		this.reliableUDPSocket = reliableUDPSocket;
		this.timeout = timeout;
		this.cancel = false;
	}
	
	public void cancel()
	{
		this.cancel = true;
	}
	
	public void run()
	{
		try 
		{
			Thread.sleep(timeout);
			
			// notify re-send 
			if (cancel == false)
			{
				reliableUDPSocket.timerUpdate();
			}
		} 
		catch (InterruptedException e) 
		{
			e.printStackTrace();
		}
	}
}